<template>
  <a-tag v-if="tag" :color="tag.color">
    {{ isFunction(tag.text) ? tag.text() : tag.text }}
  </a-tag>
</template>
<script lang="ts" setup>
import { computed } from "vue";
import { isFunction } from "lodash";
import type { StatusListOption } from "./typing";
import { useI18n } from "vue-i18n";

interface Props {
  /**枚举数据 */
  statusList?: StatusListOption[];
  /**展示值 */
  value: string;
}
const props = defineProps<Props>();
const { t } = useI18n();
const defaultStatusList: StatusListOption[] = [
  { text: () => t("有效"), value: "Y", color: "green" },
  { text: () => t("无效"), value: "N", color: "red" },
];
const tag = computed(() => {
  const list = props.statusList || defaultStatusList;
  return list.find((f: StatusListOption) => f.value == props.value);
});
</script>
